package com.eastfair.venueservice.service.impl;

import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.venuebooking.api.ExhibitionSpaceFeign;
import com.eastfair.venuebooking.vo.ExhibitionSpaceVO;
import com.eastfair.venueservice.entity.ExhibitionManage;
import com.eastfair.venueservice.service.ExhibitionManageService;
import com.eastfair.venueservice.service.VenueManageExhibitionSpaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 场馆预定 展会展厅 服务.
 *
 * @author dqq
 * @date 2022 /11/7
 */
@Service
@Slf4j
public class VenueManageExhibitionSpaceServiceImpl implements VenueManageExhibitionSpaceService {

    @Resource
    private ExhibitionSpaceFeign exhibitionSpaceFeign;

    @Resource
    private ExhibitionManageService exhibitionManageService;

    @Override
    public List<ExhibitionSpaceVO> queryByExhibitionId(Long exhibitionId) {
        log.info("queryByExhibitionId - 场馆预定展会ID查询展会展厅关系, exhibitionId={}", exhibitionId);
        R<List<ExhibitionSpaceVO>> result = exhibitionSpaceFeign.queryByExhibitionId(exhibitionId);
        log.info("queryByExhibitionId - 完成, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public List<ExhibitionSpaceVO> listByExhibitionManageId(Long exhibitionManageId) {
        ExhibitionManage exhibitionManage = exhibitionManageService.getById(exhibitionManageId);
        if (!Objects.nonNull(exhibitionManage)) {
            throw BizException.wrap(-1, "未找到对应展会");
        }
        return queryByExhibitionId(exhibitionManage.getVbExhibitionId());
    }
}